/**
 * Created by Administrator on 2016/10/18 0018.
 */
var express = require("express");
var router = express.Router();
var BookInfo = require("../models/bookinfo");
var Chapters = require("../models/chapter.js");

router.get("/",function(req,res,next){
    BookInfo.getBookNameList(function(err,bookNameList){
        res.render("bookList",{
            "title":"小说列表",
            "bookList":bookNameList
        });
    });
});

router.get("/bookinfo/:bookId",function(req,res){
    var bookId = req.params.bookId;
    BookInfo.getBookByBookId(bookId,function(err,book){
        res.render("book",{
            "title":book.bookName,
            "book":book
        });
    });
});

router.get("/book/:bookId/:index",function(req,res){
    var bookId = req.params.bookId;
    var index = req.params.index;
    Chapters.getChapter(bookId,index,function(err,chapter){
        if(chapter){
            res.render("chapter",{
                "title":chapter.chapterName,
                "chapter":chapter
            });
        }else{
            res.render("error",{
                "errorMsg":"找不到该章节"
            });
        }
    });
});

module.exports = router;